Skip to content

Support UDTFs in information_schema.routines / SHOW FUNCTIONS#23438

Open
zhuqi-lucas wants to merge 1 commit into
apache:mainfrom
zhuqi-lucas:qizhu/show-functions-udtf-upstream
Open

Support UDTFs in information_schema.routines / SHOW FUNCTIONS#23438
zhuqi-lucas wants to merge 1 commit into
apache:mainfrom
zhuqi-lucas:qizhu/show-functions-udtf-upstream

Conversation

@zhuqi-lucas

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Closes #23437.

Rationale for this change

information_schema.routines and SHOW FUNCTIONS currently enumerate only scalar / aggregate / window UDFs. Table functions (UDTFs) registered via SessionContext::register_udtf are omitted, making them undiscoverable through SQL. Discovery matters because downstream tooling (DataFusion CLI, Massive's atlas SQL surface, dbt-datafusion, etc.) uses these SQL surfaces to list available functions.

What changes are included in this PR?

1. Snapshot table functions into the information_schema provider.

TaskContext cannot expose table_functions without introducing a crate cycle (TableFunction lives in datafusion-catalog, which depends on datafusion-execution where TaskContext lives). Instead, snapshot SessionState.table_functions into InformationSchemaProvider at construction time. The provider is built per-query via schema_for_ref, so the snapshot stays fresh.

2. Emit UDTF rows.

  • make_routines: one row per UDTF with routine_type = \"FUNCTION\", function_type = \"TABLE\", data_type = \"TABLE\".
  • make_parameters: a single synthetic OUT row per UDTF (data_type = \"TABLE\") so the JOIN in SHOW FUNCTIONS resolves. UDTFs have no scalar signature, so no IN rows are emitted.

3. Rewrite the SHOW FUNCTIONS SQL.

The old query joined parameters p (INNER) requiring both IN and OUT rows before joining routines. UDTFs have no IN parameters, so they fell out. New shape:

```
FROM (parameters WHERE mode='OUT') o
LEFT JOIN (parameters WHERE mode='IN') i
ON matching keys
JOIN information_schema.routines r
ON name matches
```

Are these changes tested?

Verified locally by registering a UDTF and running SHOW FUNCTIONS:

```

SHOW FUNCTIONS LIKE 'stale%'
+---------------+-------------+---------------+
| function_name | return_type | function_type |
| stale_files | TABLE | TABLE |
+---------------+-------------+---------------+
```

Happy to add sqllogictests in datafusion/sqllogictest/test_files/information_schema.slt if maintainers prefer.

Are there any user-facing changes?

Yes: SHOW FUNCTIONS output now includes table functions. information_schema.routines and information_schema.parameters gain rows for each registered UDTF. Existing rows are unchanged.

Copilot AI review requested due to automatic review settings July 10, 2026 07:10
@github-actions github-actions Bot added sql SQL Planner core Core DataFusion crate catalog Related to the catalog crate labels Jul 10, 2026
@zhuqi-lucas zhuqi-lucas force-pushed the qizhu/show-functions-udtf-upstream branch from f297568 to 55cb62d Compare July 10, 2026 07:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends DataFusion’s SQL discovery surfaces to include table functions (UDTFs) in information_schema.routines and SHOW FUNCTIONS, addressing the gap where only scalar/aggregate/window UDFs were listed.

Changes:

  • Snapshot SessionState.table_functions into InformationSchemaProvider so UDTFs can be exposed without introducing crate cycles.
  • Emit information_schema.routines and information_schema.parameters rows for UDTFs (synthetic OUT parameter row with data_type = 'TABLE').
  • Rewrite SHOW FUNCTIONS SQL to start from OUT parameter rows and LEFT JOIN IN parameter rows so functions with no inputs can appear.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
datafusion/sql/src/statement.rs Rewrites SHOW FUNCTIONS to be compatible with functions that lack IN parameters (e.g., UDTFs).
datafusion/core/src/execution/session_state.rs Passes the session’s registered table functions into the per-query InformationSchemaProvider.
datafusion/catalog/src/information_schema.rs Stores table functions in InformationSchemaConfig and emits corresponding routines / parameters rows.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +2646 to 2649
o.specific_name function_name,
o.data_type return_type,
array_agg(i.parameter_name ORDER BY i.ordinal_position ASC) parameters,
array_agg(i.data_type ORDER BY i.ordinal_position ASC) parameter_types
Comment on lines +320 to +322
// Table functions (UDTFs) don't have scalar signatures; their return
// type is always a table, so emit a single row per UDTF with
// routine_type = "TABLE" and data_type = "TABLE".
Comment thread datafusion/sql/src/statement.rs Outdated
Comment on lines 2634 to 2636
// Note: use LEFT JOIN from OUT rows to IN rows so functions without
// input parameters (notably UDTFs / table functions) still appear.
let query = format!(
@zhuqi-lucas zhuqi-lucas force-pushed the qizhu/show-functions-udtf-upstream branch from 55cb62d to 3ede8a3 Compare July 10, 2026 07:35
@github-actions github-actions Bot added the sqllogictest SQL Logic Tests (.slt) label Jul 10, 2026
@zhuqi-lucas zhuqi-lucas force-pushed the qizhu/show-functions-udtf-upstream branch from 3ede8a3 to 129e008 Compare July 10, 2026 07:58
- add table_functions field to InformationSchemaConfig + builder
- emit UDTFs from make_routines (function_type=TABLE, data_type=TABLE)
- emit synthetic OUT parameter for UDTFs so JOIN in SHOW FUNCTIONS resolves
- rewrite SHOW FUNCTIONS SQL as OUT LEFT JOIN IN so args-less UDTFs surface
- wire SessionState.table_functions snapshot into InformationSchemaProvider
@zhuqi-lucas zhuqi-lucas force-pushed the qizhu/show-functions-udtf-upstream branch from 129e008 to 3fb1e9a Compare July 10, 2026 08:35
@xudong963 xudong963 self-requested a review July 10, 2026 10:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

catalog Related to the catalog crate core Core DataFusion crate sql SQL Planner sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SHOW FUNCTIONS / information_schema.routines omit table functions (UDTFs)

2 participants